define(["tool"], function (tool) {
    /********************图片轮播模态框*****************/
    let ScrollPhotoComponent = function (arrayNode) {
        this.timerOne = null
        this.appendNode = null
        this.pareNode = arrayNode.pareNode
        this.pointNode = arrayNode.pointNode
        this.pointLeft = arrayNode.pointLeft
        this.pointRight = arrayNode.pointRight
    }
    ScrollPhotoComponent.prototype.setPlayLeftAndRight = function () {
        this.pointLeft.style.display = "none"
        this.pointRight.style.display = "none"
        let that = this
        this.pareNode.onmouseover = function () {
            that.pointLeft.style.display = "block"
            that.pointRight.style.display = "block"
        }
        this.pareNode.onmouseout = function () {
            that.pointLeft.style.display = "none"
            that.pointRight.style.display = "none"
        }
    }
    //设置data
    ScrollPhotoComponent.prototype.setData = function (data) {
        if (data) {
            return data
        }
    }
    ScrollPhotoComponent.prototype.setOnePhotoNode = function (func) {
        if (func) {
            this.appendNode = func
        } else {
            console.log("err" + "未传递函数")
        }
    }
    //打印所有节点
    ScrollPhotoComponent.prototype.addAllNode = function (data) {
        let arr = this.setData(data),
            div
        for (let i = 0; i < arr.length; i++) {
            div = this.appendNode(arr[i])
            this.pointNode.innerHTML += div
        }
    }
    //适应长度
    ScrollPhotoComponent.prototype.adjustWidth = function (length, data) {
        let arr = this.setData(data)
        this.pointNode.style.width = arr.length * length + "px"
        this.pointNode.style.left = "0px"
        for (let i = 0; i < this.pointNode.querySelectorAll(".item").length; i++) {
            this.pointNode.querySelectorAll(".item")[i].style.width = length - 6 + "px"
        }
    }
    //适应屏幕
    ScrollPhotoComponent.prototype.resizeToWindow = function (flag) {
        let that = this,
            flagToScroll = flag
        tool.on(window, "resize", function () {
            clearTimeout(that.timerOne)
            that.timerOne = setTimeout(function () {
                if (flagToScroll) {
                    //分享节点对应大小变化自适应
                    let nodeWidth = that.pareNode.parentNode.parentNode.clientWidth;
                    that.pointNode.style.width = that.pointNode.querySelectorAll(".item").length * nodeWidth + "px"
                    for (let i = 0; i < that.pointNode.querySelectorAll(".item").length; i++) {
                        that.pointNode.querySelectorAll(".item")[i].style.width = nodeWidth - 6 + "px"
                    }
                    //让父节点右边自适应
                    let pointRight = that.pointNode.clientWidth - Math.abs(parseInt(that.pointNode.style.left))
                    if (pointRight < that.pareNode.clientWidth) {
                        that.pointNode.style.left = -that.pointNode.clientWidth + that.pareNode.clientWidth + "px"
                    }
                } else {
                    //让父节点右边自适应
                    let pointRight = that.pointNode.clientWidth - Math.abs(parseInt(that.pointNode.style.left))
                    if (pointRight < that.pareNode.clientWidth) {
                        that.pointNode.style.left = -that.pointNode.clientWidth + that.pareNode.clientWidth + "px"
                    }
                }
            }, 5)
        })
    }
    //点击按钮滚动
    ScrollPhotoComponent.prototype.setRoll = function () {
        let that = this,
            length
        that.pointLeft.onclick = function () {
            length = parseInt(that.pointNode.style.left) + that.pareNode.clientWidth
            if (Math.abs(length) >= 0) {
                that.pointNode.style.left = 0 + "px"
                return
            }
            that.pointNode.style.left = length + "px"
        }
        that.pointRight.onclick = function () {
            length = parseInt(that.pointNode.style.left) - that.pareNode.clientWidth
            if (Math.abs(length) >= (that.pointNode.clientWidth - that.pareNode.clientWidth)) {
                that.pointNode.style.left = -(that.pointNode.clientWidth - that.pareNode.clientWidth) + "px"
                return
            }
            that.pointNode.style.left = length + "px"
        }
    }
    //初始化函数
    ScrollPhotoComponent.prototype.init = function (length, data) {
        if (this.pareNode) {
            this.setPlayLeftAndRight()
            this.addAllNode(data)
            this.adjustWidth(length, data)
            this.setRoll()
        }
    }
    return ScrollPhotoComponent
})